package com.example.baiduapi.runnable;


import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.function.Function;
import java.util.function.Supplier;


public class Branch {
    public String functionA(){
        return "A";
    }
    public JSONObject functionA1(JSONObject param){
        param.put("status","success");
        return param;
    }
    public static void main(String[] args) throws Exception {
        Branch branch = new Branch();
        Callable c = branch::test2;
        Object call = c.call();
        System.out.println(call);

    }
    public boolean test2() throws Exception {
        Thread.sleep(100000);
        return true;
    }
    public void test1(){
        Map<String, Supplier> branchCode = new HashMap<>();
        Map<String, Function<JSONObject, JSONObject>> branchCodeWithParam = new HashMap<>(); // Function的泛型为入参和返回值

        Branch branch = new Branch();
        // 方法引用
        Supplier<String> functionA = branch::functionA;
        branchCode.put("functionA", functionA);
        // 有参方法引用
        Function<JSONObject, JSONObject> functionA1 = branch::functionA1;
        branchCodeWithParam.put("functionA1", functionA1);
        JSONObject resultA1 = branchCodeWithParam.get("functionA1").apply(new JSONObject());
        System.out.println(resultA1); // 输出 "Hello"

        // 获取返回值
        String result = functionA.get();
        System.out.println(result);
    }



}
